package com.csdj.questions.config;

import com.csdj.questions.service.RedisService;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * web相关的配置类
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Resource
    private RedisService redisService;

//    /**
//     * 配置拦截器
//     * @param registry
//     */
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(new LoginInterceptor(redisService))
//                .addPathPatterns("/**")//需要拦截的路径
//                .excludePathPatterns("/user/login","/user/register","/assets/**","/carousel/selectCarouselAll","/mail/send");//不需要拦截的路径
//    }
//
//    @Override
//    public void addViewControllers(ViewControllerRegistry registry) {
//        registry.addViewController("/user");
//    }
    /**
     * 添加静态资源处理程序
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
//        图片放在resource/static/下面
//        访问直接ip:端口/图片名称.后缀 //示例: http://localhost:8082/api/assets/1.jpg
//        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/assets/**").addResourceLocations("file:D:/upload/");
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }
}
